import axios from "axios";
import { requestInterceptors, responseInterceptors } from "./interceptor";
import download from "./download";
import { getUserInfo } from "@/utils/auth";
axios.defaults.headers["Content-Type"] = "application/json;charset=utf-8";

const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
  timeout: 10000,
});

const configParams = () => {
  const userInfo = getUserInfo();
  if (userInfo && userInfo.mid) {
    return {
      user: userInfo.userId,
      m: userInfo.mid,
    };
  }
};

requestInterceptors(service, configParams);

responseInterceptors(service);

export const commondownload = download(service);

export default service;
